﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace SdmxMl.Helper
{
    public class ImageHelper
    {
        public static string GetStringFromPngImage(Image image)
        {
            using (MemoryStream myStream = new MemoryStream())
            {
                image.Save(myStream, ImageFormat.Png);
                return Convert.ToBase64String(myStream.ToArray());
            }
        }

        public static Image GetPngImageFromString(string image)
        {
            byte[] imageAsBytes = System.Convert.FromBase64String(image);
            using (MemoryStream myStream = new MemoryStream(imageAsBytes, 0, imageAsBytes.Length))
            {
                myStream.Write(imageAsBytes, 0, imageAsBytes.Length);
                return Image.FromStream(myStream, true);
            }
        }
    }
}
